﻿using DDDEF.Infrastructure;
using DDDEF.Infrastructure.Caching;
using DDDEF.Infrastructure.Data;
using DDDEF.Infrastructure.Domain.Musics;
using System.Linq;

namespace DDDEF.Domain.Services
{
    public class MusicService : IMusicService
    {
        #region Fields

        private readonly IRepository<Music> _musicRepository;
        private readonly IStaticCacheManager _cacheManager;
        #endregion

        #region Construtors

        public MusicService(IRepository<Music> musicRepository,
            IStaticCacheManager cacheManager)
        {
            this._musicRepository = musicRepository;
            this._cacheManager = cacheManager;
        }

        #endregion

        public IQueryable<Music> GetAll()
        {
            return _musicRepository.TableNoTracking;
        }

        public void Insert(Music music)
        {
            _musicRepository.Insert(music);


            var cacheKey = "MUSIC_CACHE_KEY";
            _cacheManager.RemoveByPattern(cacheKey);
        }
    }
}
